//
//  UIButton+Extensions.swift
//  Swift微博
//
//  Created by 陈竹 on 16/2/24.
//  Copyright © 2016年 陈竹. All rights reserved.
//

import UIKit


extension UIButton{

    ///  button的便利构造函数
    ///
    ///  - parameter title:         文字
    ///  - parameter fontSize:      字体大小
    ///  - parameter color:        字体颜色
    ///  - parameter imageName:     图片名字
    ///  - parameter backImageName: 背景图片名字
    ///
    ///  - returns: UIbutton
    convenience init(title:String?,
        fontSize:CGFloat=17,
        color:UIColor=UIColor.darkGrayColor(),
        imageName:String?=nil,
        backImageName:String?=nil){
            
            self.init()
            self.setTitle(title, forState: .Normal)
            self.titleLabel?.font=UIFont.systemFontOfSize(fontSize)
            self.setTitleColor(color, forState: .Normal);
            
            if let imageName=imageName{
                self.setImage(UIImage(named: imageName), forState: .Normal);
                self.setImage(UIImage(named: imageName+"_selected"), forState: .Highlighted)
            }
            if let backImageName=backImageName{
                self.setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
                self.setBackgroundImage(UIImage(named: backImageName+"_selected"), forState: .Highlighted);
            }
            
            sizeToFit()
            
    }
    
}